<?php
/* Application_Form_Buyer class
 * Class Untuk Membuat Form untuk entity Buyer
 * Author Radhityo Rujito
 * PT BitZero Informatika
 */
class Application_Form_Buyer_Buyer extends Zend_Form
{
    private $province = array(
        "Aceh","Bali","Banten","Bengkulu","D.I. Yogyakarta","D.K.I. Jakarta","Gorontalo","Jambi",
        "Jawa Barat","Jawa Tengah","Jawa Timur","Kalimantan Barat","Kalimantan Selatan",
        "Kalimantan Tengah","Kalimantan Timur","Kepulauan Bangka Belitung","Kepulauan Riau",
        "Lampung","Maluku","Maluku Utara","Nusa Tenggara Barat","Nusa Tenggara Timur","Papua",
        "Papua Barat","Riau","Sulawesi Barat","Sulawesi Selatan","Sulawesi Tengah","Sulawesi Tenggara",
        "Sulawesi Utara","Sumatera Barat","Sumatera Selatan","Sumatera Utara"
    );

    public function init()
    {
        $this->setName('buyer');//set the Form Name to Buyer
        /*Create Form Object buyerID
         * set filter = Must be an Integer
         */
          $buyer_id=new Zend_Form_Element_Hidden('buyer_id');
          $buyer_id->addFilter('Int');

          /* Create Form Object Name => Buyer Name
           * Filter :
           * 1. cannot input HTML Tags
           * 2. delete spaces at the beginning and  the end of buyer's name
           */
          $name = new Zend_Form_Element_Text('name');
          $name->setRequired(true)
                ->addFilter('stripTags')
                ->addFilter('stringTrim')
                ->setAttrib('maxlength', '30')
                ->addErrorMessages(array('notEmpty'=>'Mohon Isi Nama Anda'));

          /* Create Form Object Address => Buyer's Address
           * Filter :
           * 1. cannot input HTML Tags
           * 2. delete spaces at the beginning and  the end of buyer's name
           */
          $address = new Zend_Form_Element_Textarea('address');
          $address->setRequired(true)
                  ->addFilter('stripTags')
                  ->addFilter('stringTrim')
                  ->setAttrib('maxlength', '50')
                  ->setAttrib('cols', '30')
                  ->addValidator('NotEmpty')
                  ->addErrorMessages(array('notEmpty'=>'Mohon isi alamat rumah anda'))
                  ->setAttrib('rows', '4');

          /*Create Form Object Email => Buyer's email
           * 1. cannot input HTML Tags
           * 2. delete spaces at the beginning and  the end of buyer's name
           * 3. Set String To Lower Case
           */
          $email = new Zend_Form_Element_Text('email');
          $email->setRequired(false)
                 ->addFilter('stripTags')
                  ->addFilter('stringTrim')
                  ->addFilter('StringToLower')
                  ->addValidators(array('EmailAddress'=>'EmailAddress'))
                  ->addErrorMessages(array('EmailAddress'=>'Format email anda salah'))
                  ->setAttrib('maxlength', '100');
          /*
           * Create Object Form Gender => Buyer's Gender
           * Filter:
           * 1. required
           * Option:
           * Laki-Laki
           * Perempuan
           */
          $gender = new Zend_Form_Element_Select('gender');
          $gender->setRequired(false)
                  ->addMultiOptions(array('Laki-Laki'=>'Laki-Laki',
                                           'Perempuan'=>'Perempuan'));

          $active = new Zend_Form_Element_Select('active');
          $active->setRequired(false)
                  ->addMultiOptions(array('0'=>'Belum Aktif',
                                           '1'=>'Aktif'));
          /*
           * Create Object Form Password => Buyer's Password
           *
           */
          $password = new Zend_Form_Element_Password('password');
          $password->setRequired(true)
                   ->addFilter('stripTags')
                   ->addFilter('stringTrim')
                   ->addValidator('NotEmpty')
                   ->addErrorMessages(array('notEmpty'=>'Mohon isi kolom password'))
                   ->setAttrib('maxlength', '16');
          /*
           * Create Object Form Username => buyer's username
           * Filter :
           * 1. cannot input HTML Tags
           * 2. delete spaces at the beginning and  the end of buyer's name
           */
          $username = new Zend_Form_Element_Text('username');
          $username->setRequired(true)
                   ->addFilter('stripTags')
                   ->addFilter('stringTrim')
                   ->addValidator('NotEmpty')
                   ->addErrorMessages(array('notEmpty'=>'Mohon isi kolom username'))
                   ->setAttrib('maxlength', '20');
          /*
           * Create Object Form homePhone
           *
           */
           $home_phone = new Zend_Form_element_text('home_phone');
           $home_phone ->setRequired(false)
                      ->addFilter('stripTags')
                      ->addFilter('stringTrim')
                      ->addValidator('NotEmpty')
                      ->addValidator("regex",false,array('pattern' => "/^0([0-9]{1,3}-)?[0-9]{6,}$/"))
                       ->setAttrib("maxLength","15")
                       ->addErrorMessages(array("regex"=>"Mohon isilah format nomor telepon dengan benar"));
           /*
           * Create Object Form dob
           *
           */
           $date_birth= new Zend_Form_element_text('date_birth');
           $date_birth ->setRequired(true)
                ->addFilter('stripTags')
                ->addValidator('NotEmpty')
                ->addErrorMessages(array('notEmpty'=>'Mohon isi tanggal kelahiran anda'))
                ->addFilter('stringTrim');
          /*
           * Create Object Form Avatar
           * Validator:
           * size must be less or equal than 102400 bytes
           * file extension must be jpg,png, or gif
           */
          $avatar = new Zend_Form_Element_File('avatar');
          $avatar ->addValidator('Count', false, 1)
                  ->addValidator('Size', false, 102400)
                  ->addValidator('Extension', false, 'jpg,png,gif')
                  ->addErrorMessage(array("error"
                                         =>"Mohon upload avatar dengan extension
                                            .jpg,.png atau .gif"));

           /*
            * Create Object Form handphone
            */
           $mobile_phone = new Zend_form_element_text('mobile_phone');
           $mobile_phone ->setRequired(true)
                      ->addFilter('stripTags')
                      ->addFilter('stringTrim')
                      ->addValidator("regex",false,array('pattern' => "/^0([0-9]{1,3}-)?[0-9]{6,}$/"))
                       ->setAttrib("maxLength","15")
                       ->addErrorMessages(array("regex"=>"Mohon isilah format nomor telepon dengan benar"));
        
           /*
            * Create Object Form Submit Button
            *
            */

           $submit = new Zend_Form_Element_Submit('submit');
           $submit->setAttrib('id', 'submitBuyer');
           /*
            * Create Object Form Reset Button
            */
           $reset = new Zend_Form_Element_Reset('reset');
           $reset->setAttrib('id','resetBuyer');

        //Shop's city
        $city = new Zend_Form_Element_Text("city");
        $city->setLabel("Kota")
             ->setRequired("true")
             ->addFilter("StripTags")
             ->addFilter("StringTrim")
             ->addValidator("NotEmpty")
             ->setAttrib("maxLength","15")
             ->addErrorMessages(array("NotEmpty"=>"Mohon isi kota"));

        //Shop's province
        $provinces = array();
        foreach($this->province as $val){
            $provinces[$val] = $val;
        }
        $provinces["Lainnya"] = "Lainnya";
        $province = new Zend_Form_Element_Select("province");
        $province->setLabel("Provinsi")
             ->setRequired()
             ->addMultiOptions($provinces);

        //Shop's zip code
        $zip = new Zend_Form_Element_Text("zip");
        $zip->setLabel("Kode pos")
             ->setRequired("true")
             ->addFilter("StripTags")
             ->addFilter("StringTrim")
             ->addValidator("NotEmpty")
             ->addValidator("Digits")
             ->setAttrib("maxLength","5")
             ->addErrorMessages(array("NotEmpty"=>"Mohon isi kode pos dengan benar"));

             $this->addElements(array($buyer_id,$username,$avatar,$password,$email,$name,
                                    $gender,$date_birth,$address,$city,$province,$zip
                                    ,$home_phone,$mobile_phone,
                                     $active,$submit,$reset));
            
              
    }

}

